object QuickSort {
	

  def sort(a: List[Int]): List[Int] = {
    
	  println("sort -> " + a)
	  
	  if (a.length < 2)
      a
    else {
      val pivot = a(a.length / 2)
      println("pivot = " + pivot)
      println("a = " + a)

      def lePivot(x: Int) = x < pivot
      def gtPivot(x: Int) = x > pivot
      def eqPivot(x: Int) = x == pivot     
            
      println("a filter lePivot => " + a.filter(lePivot))
      println("a filter eqPivot => " + a.filter(eqPivot))
      println("a filter gtPivot => " + a.filter(gtPivot))
      
      sort(a.filter(lePivot)):::
      sort(a filter eqPivot) :::   
      sort(a filter gtPivot)
    }
  }

  def main(args: Array[String]) {
    val xs = List(6, 2, 8, 5, 1, 10)
    println(xs)
    println(sort(xs))
  }
  
}
